package com.example.demo.interview;

public class MySynchronized {

    public static void main(String[] args) {
        Phone p1 = new Phone();
        Phone p2 = new Phone();
        new Thread(p1::send,"A").start();
        new Thread(p2::call,"B").start();
    }
}


class Phone{


    public void send(){
        synchronized (this){
            System.out.println(Thread.currentThread().getName()+"->send");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void call(){
        synchronized (this){
            System.out.println(Thread.currentThread().getName()+"->call");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}